package Application.Writer;

import Application.MethodObject.DefGuns;
import Application.MethodObject.DefTings;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class XamlWriter {
    public static void ThingsWriter(DefTings def, File file) throws IOException {
        try(BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
            writer.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
            writer.write("<ThingDef>\n");
            writer.write("  <thingClass>ThingWithComps</thingClass>\n");
            writer.write("  <category>Item</category>\n");
            writer.write("  <drawerType>MapMeshOnly</drawerType>\n");
            writer.write("  <resourceReadoutPriority>Middle</resourceReadoutPriority>\n");
            writer.write("  <defName>"+def.defName+"</defName>\n");
            writer.write("  <label>"+def.label+"</label>\n");
            writer.write("  <description>"+def.description+"</description>\n");
            writer.write("  <graphicData>\n");
            writer.write("    <texPath>"+def.texPath+"</texPath>\n");
            writer.write("    <graphicClass>Graphic_StackCount</graphicClass>\n");
            writer.write("  </graphicData>\n");
            writer.write("  <soundInteract>Metal_Drop</soundInteract>\n");
            writer.write("  <soundDrop>Standard_Drop</soundDrop>\n");
            writer.write("  <stackLimit>"+def.stackLimit+"</stackLimit>\n");
            writer.write("  <useHitPoints>"+def.useHitPoints+"</useHitPoints>\n");
            writer.write("  <selectable>"+def.selectable+"</selectable>\n");
            writer.write("  <altitudeLayer>Item</altitudeLayer>\n");
            writer.write("  <healthAffectsPrice>"+def.healthAffectsPrice+"</healthAffectsPrice>\n");
            writer.write("  <statBases>\n");
            if (def.useHitPoints)
            {
            writer.write("    <MaxHitPoints>"+def.maxHitPoints+"</MaxHitPoints>\n");
            }
            writer.write("    <MarketValue>"+def.marketValue+"</MarketValue>\n");
            writer.write("    <Mass>"+def.mass+"</Mass>\n");
            writer.write("    <Flammability>"+def.flammability+"</Flammability>\n");
            writer.write("    <DeteriorationRate>"+def.deteriorationRate+"</DeteriorationRate>\n");
            writer.write("  </statBases>\n");
            writer.write("  <alwaysHaulable>"+def.alwaysHaulable+"</alwaysHaulable>\n");
            writer.write("  <drawGUIOverlay>"+def.drawGUIOverlay+"</drawGUIOverlay>\n");
            writer.write("  <rotatable>"+def.rotatable+"</rotatable>\n");
            writer.write("  <pathCost>"+def.pathCost+"</pathCost>\n");
            writer.write("  <thingCategories> \n");
            writer.write("    <li>"+def.thingCategories+"</li>\n");
            writer.write("  </thingCategories>\n");
            writer.write("  <tradeTags>\n");
            writer.write("    <li>"+def.tags+"</li>\n");
            writer.write("  </tradeTags>\n");
            writer.write("  <thingSetMakerTags>\n");
            writer.write("    <li>"+def.thingSetMakerTags+"</li>\n");
            writer.write("  </thingSetMakerTags>\n");
            writer.write("  <comps>\n");
            writer.write("    <li Class=\"CompProperties_Forbiddable\"/>\n");
            writer.write("  </comps>\n");
            writer.write("</ThingDef>");
        }catch (Exception e)
        {
            e.printStackTrace();
            throw e;
        }
    }

    public static void GunsWriter(DefGuns def, File file) throws IOException {
        try(BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
            writer.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
                    "<!-- 子弹的数据 -->\n" +
                    "<Defs>\n" +
                    "<!-- 继承了哪个物品 -->\n" +
                    "  <ThingDef ParentName=\""+ def.bullet_ParentName +"\">\n" +
                    "    <!-- 代码中物品的名字 -->\n" +
                    "    <defName>"+ def.bullet_defName +"</defName>\n" +
                    "    <!-- 游戏中物品显示的名字 -->\n" +
                    "    <label>"+ def.bullet_label +"</label>\n" +
                    "    <graphicData>\n" +
                    "      <!-- 使用的纹理贴图 -->\n" +
                    "      <texPath>"+ def.bullet_texPath +"</texPath>\n" +
                    "      <!-- 使用哪个图形类的代码 -->\n" +
                    "      <graphicClass>Graphic_Single</graphicClass>\n" +
                    "    </graphicData>\n" +
                    "    <projectile>\n" +
                    "    <!-- 子弹类型 -->\n" +
                    "      <damageDef>"+def.bullet_damageDef+"</damageDef>\n" +
                    "      <!-- 子弹基础伤害 -->\n" +
                    "      <damageAmountBase>"+def.bullet_damageAmountBase+"</damageAmountBase>\n" +
                    "      <!-- 取消射击的反应速度 -->\n" +
                    "      <stoppingPower>"+def.bullet_stoppingPower+"</stoppingPower>\n" +
                    "      <!-- 子弹的速度 -->\n" +
                    "      <speed>"+def.bullet_speed+"</speed>\n" +
                    "    </projectile>\n" +
                    "  </ThingDef>\n" +
                    "  <!-- 枪的数据 -->\n" +
                    "  <ThingDef ParentName=\""+def.gun_ParentName+"\">\n" +
                    "    <defName>"+def.gun_defName+"</defName>\n" +
                    "    <label>"+def.gun_label+"</label>\n" +
                    "    <!-- 描述 -->\n" +
                    "    <description>"+def.gun_description+"</description>\n" +
                    "    <graphicData>\n" +
                    "      <texPath>"+def.gun_texPath+"</texPath>\n" +
                    "      <graphicClass>Graphic_Single</graphicClass>\n" +
                    "    </graphicData>\n" +
                    "    <!-- UI缩放 -->\n" +
                    "    <uiIconScale>"+def.gun_uiIconScale+"</uiIconScale>\n" +
                    "    <soundInteract>Interact_Revolver</soundInteract>\n" +
                    "    <!-- 个人猜测是艺术系统的标签 -->\n" +
                    "    <thingSetMakerTags><li>"+def.gun_thingSetMakerTags+"</li></thingSetMakerTags>\n" +
                    "    <!-- 基础属性 -->\n" +
                    "    <statBases>\n" +
                    "    <!-- 制作的工作量 -->\n" +
                    "      <WorkToMake>"+def.gun_WorkToMake+"</WorkToMake>\n" +
                    "      <!-- 物品大小 -->\n" +
                    "      <Mass>"+ def.gun_Mass+"</Mass>\n" +
                    "      <!-- 贴脸的命中率 -->\n" +
                    "      <AccuracyTouch>"+def.gun_AccuracyTouch+"</AccuracyTouch>\n" +
                    "      <!-- 短距离命中率 -->\n" +
                    "      <AccuracyShort>"+def.gun_AccuracyShort+"</AccuracyShort>\n" +
                    "      <!-- 中距离命中率 -->\n" +
                    "      <AccuracyMedium>"+def.gun_AccuracyMedium+"</AccuracyMedium>\n" +
                    "      <!-- 远距离命中率 -->\n" +
                    "      <AccuracyLong>"+def.gun_AccuracyLong+"</AccuracyLong>\n" +
                    "      <RangedWeapon_Cooldown>"+def.gun_RangedWeapon_Cooldown+"</RangedWeapon_Cooldown>\n" +
                    "    </statBases>\n" +
                    "    <!-- 武器标签 -->\n" +
                    "    <weaponTags>\n" +
                    def.gun_weaponTags+
                    "    </weaponTags>\n" +
                    "    <!-- 消耗列表 -->\n" +
                    "    <costList>\n" + def.gun_costList+
                    "    </costList>\n" +
                    "    <recipeMaker>\n" +
                    "    <!-- 技能需求 -->\n" +
                    "      <skillRequirements>\n" +
                    "        <Crafting>"+def.gun_skillRequirements_Craft+"</Crafting>\n" +
                    "      </skillRequirements>\n" +
                    "    </recipeMaker>\n" +
                    "    <!-- 动作 -->\n" +
                    "    <verbs>\n" +
                    "      <li>\n" +
                    "      <!-- 射击 -->\n" +
                    "        <verbClass>Verb_Shoot</verbClass>\n" +
                    "        <!-- 是否有标准命令 -->\n" +
                    "        <hasStandardCommand>"+def.gun_hasStandardCommand+"</hasStandardCommand>\n" +
                    "        <!-- 子弹类型 -->\n" +
                    "        <defaultProjectile>"+def.bullet_defName+"</defaultProjectile>\n" +
                    "        <!-- 预热时间 -->\n" +
                    "        <warmupTime>"+def.gun_warmupTime+"</warmupTime>\n" +
                    "        <!-- 射击距离 -->\n" +
                    "        <range>"+def.gun_range+"</range>\n" +
                    "        <!-- 射击时使用的音效 -->\n" +
                    "        <soundCast>"+def.gun_soundCast+"</soundCast>\n" +
                    "        <!-- 中弹时的音效 -->\n" +
                    "        <soundCastTail>"+def.gun_soundCastTail+"</soundCastTail>\n" +
                    "        <!-- 枪口光效的缩放 -->\n" +
                    "        <muzzleFlashScale>"+def.gun_muzzleFlashScale+"</muzzleFlashScale>\n" +
                    "      </li>\n" +
                    "    </verbs>\n" +
                    "    <tools>\n" +
                    "      <li>\n" +
                    "        <label>grip</label>\n" +
                    "        <capacities>\n" +
                    "          <li>Blunt</li>\n" +
                    "        </capacities>\n" +
                    "        <power>9</power>\n" +
                    "        <cooldownTime>2</cooldownTime>\n" +
                    "      </li>\n" +
                    "      <li>\n" +
                    "        <label>barrel</label>\n" +
                    "        <capacities>\n" +
                    "          <li>Blunt</li>\n" +
                    "          <li>Poke</li>\n" +
                    "        </capacities>\n" +
                    "        <power>9</power>\n" +
                    "        <cooldownTime>2</cooldownTime>\n" +
                    "      </li>\n" +
                    "    </tools>\n" +
                    "  </ThingDef>\n" +
                    "</Defs>");
        }catch (Exception e)
        {
            e.printStackTrace();
            throw e;
        }
    }
}
